import random
import sys
import pygame
from settings import Settings
from bucket import Bucket
from drop import Drop
from pygame.sprite import Group
import game_functions as gf
import time

def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    dg_settings = Settings()
    screen = pygame.display.set_mode((dg_settings.screen_width,dg_settings.screen_height))
    pygame.display.set_caption("接水滴")

    # 设置背景色
    bg_color = dg_settings.bg_color

    # 创建一个水桶对象
    bucket = Bucket(dg_settings, screen)
    # 创建一个雨滴数组
    drops = Group()


    pygame.mixer.init()
    pygame.mixer.music.load('audio/rain.mp3')
    pygame.mixer.music.set_volume(10)
    pygame.mixer.music.play(-1)
    # 开始游戏的主循环
    while True:
        # 监视键盘和鼠标事件
        gf.cheeck_events(bucket)
        bucket.update()
        randomInt = 5
        if randomInt == random.randint(1,600):
            drop = Drop(dg_settings,screen)
            drops.add(drop)
        for drop in drops:
            drop.update()
        gf.check_bottom_drops(screen,drops)
        gf.check_beat(bucket,drops)
        # 每次循环时重绘屏幕
        gf.update_screen(dg_settings, screen, bucket,drops)

run_game()